import 'dart:async';

import 'package:flutter/services.dart';

class Screen {
  static const MethodChannel _channel =
      const MethodChannel('github.com/clovisnicolas/flutter_screen');

  static Future<double> get brightness async {
    try {
      return (await _channel.invokeMethod<double>('brightness')) ?? 0.0;
    } catch (e) {
      return 0.0;
    }
  }

  static Future<void> setBrightness(double brightness) async {
    try {
      await _channel
          .invokeMethod<void>('setBrightness', {'brightness': brightness});
    } catch (e) {
      // Handle error
    }
  }

  static Future<bool> get isKeptOn async {
    try {
      return (await _channel.invokeMethod<bool>('isKeptOn')) ?? false;
    } catch (e) {
      return false;
    }
  }

  static Future<void> keepOn(bool on) async {
    try {
      await _channel.invokeMethod<void>('keepOn', {'on': on});
    } catch (e) {
      // Handle error
    }
  }
}
